<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head(~{::title})">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title th:text="${blog.title}">博客详情</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
  <link rel="stylesheet" href="../static/css/typo.css">
  <link rel="stylesheet" href="../static/css/animate.css">
  <link rel="stylesheet" href="../static/lib/prism/prism.css">
  <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css">
  <link rel="stylesheet" href="../static/css/me.css">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css" th:href="@{/lib/editormd/css/editormd.min.css}">
</head>
<body>

  <!--导航-->
  <nav th:replace="_fragments :: menu(0)"  class="ui inverted attached segment m-padded-tb-mini m-shadow-small" ></nav>
  <!--导航-->

  <!--顶部图片-->
  <div class="m-bg-type_outer" style="width: 100%;height: 45%">
      <img src="../static/images/bg.jpg" th:src="@{${blog.firstPicture}}" alt="" class="ui m-bg image" style="width: 100%;height: 100%">
      <div class="m-bg-class_cover">
          <div class="ui container" style="position: relative ;bottom: -540px;">
              <h2 class="m-font-size-title-large" align="center" th:text="${blog.title}">Markdown编辑</h2>
              <div class="ui container" align="center">
                  <div class="ui horizontal link list" align="center">
                      <div class="item">
                          <div class="ui orange basic label" style="font-size: 7px" th:text="${blog.flag}">原创</div>
                      </div>
                      <div class="item">
                          <i class="user outline outline icon m-font-size-text-mini"></i>
                          <a href="#" style="color: #ffffff;font-size: 15px" th:text="${blog.user.nickname}">CESARE</a>
                      </div>
                      <div class="item">
                          <i class="calendar icon m-font-size-text-mini"></i>
                          <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}" class="m-font-size-text-mini">2020-01-01</span>
                      </div>
                      <div class="item">
                          <i class="clone icon m-font-size-text-mini"></i>
                          <a href="#" target="_blank" style="color: #ffffff;font-size: 16px" th:text="${blog.type.name}">我的故事</a>
                      </div>
                      <div class="item">
                          <i class="eye icon m-font-size-text-mini"></i> <span th:text="${blog.views}" class="m-font-size-text-mini">2222</span>
                      </div>
                  </div>
              </div>
          </div>
      </div>
  </div>
  <!--顶部图片-->

  <!--中间内容-->
  <div id="waypoint" class="m-margin- animated fadeIn">
      <div class="ui container m-opacity box-shadow-max">
          <!--内容-->
          <div class="ui attached padded segment">


              <!--中间主要内容部分-->
              <div id="content" class="typo  typo-selection js-toc-content m-padded-lr-responsive m-padded-tb-large" th:utext="${blog.content}">

              </div>

              <div class="ui horizontal divider">end</div>


              <!--标签-->
              <div class="m-padded-lr-responsive">
                  <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}">方法论</div>
              </div>

              <!--赞赏-->
              <div th:if="${blog.appreciation}">
                  <div class="ui center aligned basic segment">
                      <button id="payButton" class="ui orange basic circular button">赞赏</button>
                  </div>
                  <div class="ui payQR flowing popup transition hidden">
                      <div class="ui orange basic label">
                          <div class="ui images" style="font-size: inherit !important;">
                              <div class="image">
                                  <img src="../static/images/wechat.jpg" th:src="@{/images/pay.png}" alt="" class="ui rounded bordered image" style="width: 120px">
                                  <div>支付宝</div>
                              </div>
                              <div class="image">
                                  <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt="" class="ui rounded bordered image" style="width: 120px">
                                  <div>微信</div>
                              </div>
                          </div>
                      </div>
                  </div>
              </div>

          </div>
          <div class="ui attached positive message" th:if="${blog.shareStatement}">
              <!--博客信息-->
              <div class="ui middle aligned grid">
                  <div class="eleven wide column">
                      <ui class="list">
                          <li>作者：<span th:text="${blog.user.nickname}">Cesare</span><a href="#" th:href="@{/about}" target="_blank">（联系作者）</a></li>
                          <li>发表时间：<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2020-10-02 09:08</span></li>
                          <li>版权声明：自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
                          <li>公众号转载：请在文末添加作者公众号二维码</li>
                      </ui>
                  </div>
                  <div class="five wide column">
                      <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt="" class="ui right floated rounded bordered image" style="width: 110px">
                  </div>
              </div>
          </div>
          <div  class="ui bottom attached segment" th:if="${blog.commentabled}">
              <!--留言区域列表-->
              <div id="comment-container"  class="ui teal segment">
                  <div th:fragment="commentList">
                      <div class="ui threaded comments" style="max-width: 100%;">
                          <h3 class="ui dividing header">评论</h3>
                          <div class="comment" th:each="comment : ${comments}">
                              <a class="avatar">
                                  <img src="https://unsplash.it/100/100?image=1005" th:src="@{${comment.avatar}}">
                              </a>

                              <!--父评论-->
                              <div class="content">
                                  <a class="author">
                                      <span th:text="${comment.nickname}">Matt</span>
                                      <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.adminComment}">博主</div>
                                  </a>
                                  <div class="metadata">
                                      <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                  </div>
                                  <div class="text" th:text="${comment.content}">
                                      How artistic!
                                  </div>
                                  <div class="actions">
                                      <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)">回复</a>
                                      <a class="delete" href="#" th:href="@{/comment/{param1}/{param2}/delete(param1=${comment.blogId},param2=${comment.id})}" onclick="return confirm('确定要删除该评论吗？三思啊! 删了可就没了！')" >删除</a>
                                  </div>
                              </div>

                              <!--子评论-->
                              <div class="comments" th:unless="${#lists.isEmpty(comment.childComments)}">
                                  <div class="comment" th:each="reply : ${comment.childComments}">
                                      <a class="avatar">
                                          <img src="https://unsplash.it/100/100?image=1005" th:src="@{${reply.avatar}}">
                                      </a>
                                      <div class="content">
                                          <a class="author" >
                                              <span th:text="${reply.nickname}">小红</span>
                                              <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${reply.adminComment}">博主</div>
                                              &nbsp;<span th:text="|@ ${reply.replyName}|" class="m-teal">@ 小白</span>
                                          </a>
                                          <div class="metadata">
                                              <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                          </div>
                                          <div class="text" th:text="${reply.content}">
                                              How artistic!
                                          </div>
                                          <div class="actions">
                                              <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)">回复</a>
                                              <a class="delete" href="#" th:href="@{/comment/{param1}/{param2}/delete(param1=${comment.blogId},param2=${comment.id})}" onclick="return confirm('确定要删除该评论吗？三思啊! 删了可就没了！')" >删除</a>
                                              <!--<a class="delete" href="#" th:href="@{/comment/{id}/delete(id=${comment.id})}" onclick="return confirm('确定要删除该评论吗？三思啊! 删了可就没了！')" th:if="${session.user}">删除</a>-->
                                          </div>
                                      </div>
                                  </div>
                              </div>
                          </div>
                      </div>
                  </div>
              </div>
              <div id="comment-form" class="ui form">
                  <input type="hidden" name="blog.id" th:value="${blog.id}">
                  <input type="hidden" name="parentCommentId" value="-1">
                  <input type="hidden" name="replyName" value="">
                  <div class="field">
                      <textarea name="content" placeholder="请输入评论信息..."></textarea>
                  </div>
                  <div class="fields">
                      <div class="field m-mobile-wide m-margin-bottom-small">
                          <div class="ui left icon input">
                              <i class="user icon"></i>
                              <input type="text" name="nickname" placeholder="姓名" th:value="${session.user}!=null ? ${session.user.nickname}">
                          </div>
                      </div>
                      <div class="field m-mobile-wide m-margin-bottom-small">
                          <div class="ui left icon input">
                              <i class="mail icon"></i>
                              <input type="text" name="email" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}">
                          </div>
                      </div>
                      <div class="field  m-margin-bottom-small m-mobile-wide">
                          <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"><i class="edit icon"></i>发布</button>
                      </div>
                  </div>

              </div>
          </div>
      </div>
  </div>
  <!--中间内容-->

  <div id="toolbar" class="m-padded m-fixed m-right-bottom" style="display: none">
    <div class="ui vertical icon buttons ">
      <button type="button" class="ui toc teal button" >目录</button>
      <a href="#comment-container" class="ui teal button" >留言</a>
      <button class="ui wechat icon button"><i class="weixin icon"></i></button>
      <div id="toTop-button" class="ui icon button" ><i class="chevron up icon"></i></div>
    </div>
  </div>

  <div class="ui toc-container flowing popup transition hidden" style="width: 250px!important;">
    <ol class="js-toc">

    </ol>
  </div>

  <div id="qrcode" class="ui wechat-qr flowing popup transition hidden " style="width: 130px !important;">
    <!--<img src="./static/images/wechat.jpg" alt="" class="ui rounded image" style="width: 120px !important;">-->
  </div>



  <br>
  <br>
  <!--底部footer-->
  <footer th:replace="_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive">

  </footer>
  <!--底部footer-->

  <!--/*/<th:block th:replace="_fragments :: script">/*/-->
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>
  <script src="../../static/lib/editormd/editormd.min.js" th:src="@{/lib/editormd/editormd.min.js}"></script>

  <script src="../static/lib/prism/prism.js"></script>
  <script src="../static/lib/tocbot/tocbot.min.js"></script>
  <script src="../static/lib/qrcode/qrcode.min.js"></script>
  <script src="../static/lib/waypoints/jquery.waypoints.min.js"></script>
  <!--/*/</th:block>/*/-->


  <script th:inline="javascript">

    $('.menu.toggle').click(function () {
      $('.m-item').toggleClass('m-mobile-hide');
    });

    $('#payButton').popup({
      popup : $('.payQR.popup'),
      on : 'click',
      position: 'bottom center'
    });

    //目录
    tocbot.init({
      // Where to render the table of contents.
      tocSelector: '.js-toc',
      // Where to grab the headings to build the table of contents.
      contentSelector: '.js-toc-content',
      // Which headings to grab inside of the contentSelector element.
      headingSelector: 'h1, h2, h3,h4',
    });

    $('.toc.button').popup({
      popup : $('.toc-container.popup'),
      on : 'click',
      position: 'left center'
    });

    $('.wechat').popup({
      popup : $('.wechat-qr'),
      position: 'left center'
    });

    var serurl = /*[[#{blog.serurl}]]*/"127.0.0.1:8080";
    var url = /*[[@{/blog/{id}(id=${blog.id})}]]*/"";
    var qrcode = new QRCode("qrcode", {
      text: serurl+url,
      width: 110,
      height: 110,
      colorDark : "#000000",
      colorLight : "#ffffff",
      correctLevel : QRCode.CorrectLevel.H
    });
    
    $('#toTop-button').click(function () {
      $(window).scrollTo(0,500);
    });


    var waypoint = new Waypoint({
      element: document.getElementById('waypoint'),
      handler: function(direction) {
        if (direction == 'down') {
          $('#toolbar').show(100);
        } else {
          $('#toolbar').hide(500);
        }
        console.log('Scrolled to waypoint!  ' + direction);
      }
    });


    //评论表单验证
    $('.ui.form').form({
      fields: {
        title: {
          identifier: 'content',
          rules: [{
            type: 'empty',
            prompt: '请输入评论内容'
          }
          ]
        },
        content: {
          identifier: 'nickname',
          rules: [{
            type: 'empty',
            prompt: '请输入你的大名'
          }]
        },
        type: {
          identifier: 'email',
          rules: [{
            type: 'email',
            prompt: '请填写正确的邮箱地址'
          }]
        }
      }
    });

    $(function () {
      $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/"comments/6");
    });



    $('#commentpost-btn').click(function () {
      var boo = $('.ui.form').form('validate form');
      if (boo) {
        console.log('校验成功');
        postData();
      } else {
        console.log('校验失败');
      }

    });
    
    function postData() {
      $("#comment-container").load(/*[[@{/comments}]]*/"",{
        "parentCommentId" : $("[name='parentCommentId']").val(),
        "blog.id" : $("[name='blog.id']").val(),
        "nickname": $("[name='nickname']").val(),
        "email"   : $("[name='email']").val(),
        "content" : $("[name='content']").val(),
        "replyName": $("[name='replyName']").val()
      },function (responseTxt, statusTxt, xhr) {
//        $(window).scrollTo($('#comment-container'),500);

        clearContent();
      });
    }

    function clearContent() {
      $("[name='content']").val('');
      $("[name='parentCommentId']").val(-1);
      $("[name='replyName']").val("");
      $("[name='nickname']").val("");
      $("[name='email']").val("");
      $("[name='content']").attr("placeholder", "请输入评论信息...");
    }


    function reply(obj) {
      var commentId = $(obj).data('commentid');
      var commentNickname = $(obj).data('commentnickname');
      $("[name='content']").attr("placeholder", "@"+commentNickname).focus();
      $("[name='parentCommentId']").val(commentId);
      $("[name='replyName']").val(commentNickname);
      $(window).scrollTo($('#comment-form'),500);
    }

    
  </script>
</body>
</html>